package GUI;

import java.awt.*;
import javax.swing.*;

public class MainPanel extends JPanel
{
	private int chr1,chr2;
	private String background,foreground[];
	private ImageIcon icon;
	
	public MainPanel()
	{
		chr1 = chr2 = -1;
		background = "";
		foreground = new String[3];
		
		for (int i = 0;i < 3;i++)
		{
			foreground[i] = "";
		}
		
		setPreferredSize(new Dimension(800,550));
		setVisible(true);
	}
	
	public int getCharacter(boolean b)
	{
		return b?chr1:chr2;
	}
	
	public String getForeground(boolean b)
	{
		return foreground[b?chr1:chr2];
	}
	
	public void setBackground(String s)
	{
		background = s;
		repaint();
	}
	
	public void setForeground(boolean b,int i,String s)
	{
		if (b)
		{
			chr1 = i;
		}
		else
		{
			chr2 = i;
		}
		
		foreground[i] = s;
		repaint();
	}
	
	public void clear()
	{
		chr1 = chr2 = -1;
		background = "";
		
		for (int i = 0;i < 3;i++)
		{
			foreground[i] = "";
		}
		
		repaint();
	}
	
	protected void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
		if (!background.equals(""))
		{
			icon = new ImageIcon("data\\bg\\" + background + ".png");
			g.drawImage(icon.getImage(),0,0,null);
		}
		
		if (!foreground[0].equals(""))
		{
			icon = new ImageIcon("data\\chara\\" + foreground[0] + ".png");
			g.drawImage(icon.getImage(),400 - icon.getIconWidth() / 2,0,null);
		}
		
		if (!foreground[1].equals(""))
		{
			icon = new ImageIcon("data\\chara\\" + foreground[1] + ".png");
			g.drawImage(icon.getImage(),200 - icon.getIconWidth() / 2,0,null);
		}
		
		if (!foreground[2].equals(""))
		{
			icon = new ImageIcon("data\\chara\\" + foreground[2] + ".png");
			g.drawImage(icon.getImage(),600 - icon.getIconWidth() / 2,0,null);
		}
	}
}